package com.rabbitmq.workqueue;

import com.rabbitmq.client.*;
import com.rabbitmq.utils.RabbitMqUtils;

import java.io.IOException;

/**
 * @author lipengwei
 */
public class Custom02 {

    public static void main(String[] args) throws IOException {
        // 获取连接
        Connection connection = RabbitMqUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.basicQos(1);
        channel.queueDeclare("work", true, false, false, null);

        channel.basicConsume("work",false, new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者-2：" + new String(body));
                // 参数1：确认队列中那个具体的消息
                // 参数2：是否开启多个消息同时确认
                channel.basicAck(envelope.getDeliveryTag(), false);
            }
        });
        System.out.println("消费者2已经启动了……");
    }
}
